package com.shop.controller;

import com.shop.pojo.DtsArticle;
import com.shop.service.DtsArticleService;
import com.shop.util.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @ClassName AdminArticleController
 * @Author xiao宋
 * @Date 11:48  2022/10/22
 * @Version 1.0
 * @Description TODO
 */
@Slf4j
@RestController
@RequestMapping("/admin/article")
public class AdminArticleController {
    @Autowired
    DtsArticleService articleService;

    /**
     * 公告列表   <--->  通知列表
     * @param page
     * @param limit
     * @param sort
     * @param order
     * @param title
     * @return
     */
    @GetMapping("/list")
    public Object list(
            @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
            @RequestParam(value = "limit", required = false, defaultValue = "20") Integer limit,
            @RequestParam(value = "sort", required = false, defaultValue = "add_time") String sort,
            @RequestParam(value = "order", required = false, defaultValue = "desc") String order,
            String title
    ) {
        Map<String, Object> data = articleService.selectPage(page, limit, sort, order, title);
        return ResponseUtil.ok(data);
    }

    /**
     * 新增公告 -- 通知
     * @param article
     * @return
     */
    @PostMapping("/create")
    public Object create(@RequestBody DtsArticle article) {
        articleService.creat(article);
        return ResponseUtil.ok();
    }
    @PostMapping("/delete")
    public Object delete(@RequestBody DtsArticle article) {
        articleService.delete(article);
        return ResponseUtil.ok();
    }

    @PostMapping("/update")
    public Object update(@RequestBody DtsArticle article) {
        articleService.delete(article);
        return ResponseUtil.ok();
    }
}
